{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { getValue, updateValues } from \"../utils/miscUtil\";\nimport { getClosingViewDate, isSameYear, isSameMonth, isSameDecade } from \"../utils/dateUtil\";\nfunction getStartEndDistance(startDate, endDate, picker, generateConfig) {\n  var startNext = getClosingViewDate(startDate, picker, generateConfig, 1);\n  function getDistance(compareFunc) {\n    if (compareFunc(startDate, endDate)) {\n      return 'same';\n    }\n    if (compareFunc(startNext, endDate)) {\n      return 'closing';\n    }\n    return 'far';\n  }\n  switch (picker) {\n    case 'year':\n      return getDistance(function (start, end) {\n        return isSameDecade(generateConfig, start, end);\n      });\n    case 'quarter':\n    case 'month':\n      return getDistance(function (start, end) {\n        return isSameYear(generateConfig, start, end);\n      });\n    default:\n      return getDistance(function (start, end) {\n        return isSameMonth(generateConfig, start, end);\n      });\n  }\n}\nfunction getRangeViewDate(values, index, picker, generateConfig) {\n  var startDate = getValue(values, 0);\n  var endDate = getValue(values, 1);\n  if (index === 0) {\n    return startDate;\n  }\n  if (startDate && endDate) {\n    var distance = getStartEndDistance(startDate, endDate, picker, generateConfig);\n    switch (distance) {\n      case 'same':\n        return startDate;\n      case 'closing':\n        return startDate;\n      default:\n        return getClosingViewDate(endDate, picker, generateConfig, -1);\n    }\n  }\n  return startDate;\n}\nexport default function useRangeViewDates(_ref) {\n  var values = _ref.values,\n    picker = _ref.picker,\n    defaultDates = _ref.defaultDates,\n    generateConfig = _ref.generateConfig;\n  var _React$useState = React.useState(function () {\n      return [getValue(defaultDates, 0), getValue(defaultDates, 1)];\n    }),\n    _React$useState2 = _slicedToArray(_React$useState, 2),\n    defaultViewDates = _React$useState2[0],\n    setDefaultViewDates = _React$useState2[1];\n  var _React$useState3 = React.useState(null),\n    _React$useState4 = _slicedToArray(_React$useState3, 2),\n    viewDates = _React$useState4[0],\n    setInternalViewDates = _React$useState4[1];\n  var startDate = getValue(values, 0);\n  var endDate = getValue(values, 1);\n  function getViewDate(index) {\n    // If set default view date, use it\n    if (defaultViewDates[index]) {\n      return defaultViewDates[index];\n    }\n    return getValue(viewDates, index) || getRangeViewDate(values, index, picker, generateConfig) || startDate || endDate || generateConfig.getNow();\n  }\n  function setViewDate(viewDate, index) {\n    if (viewDate) {\n      var newViewDates = updateValues(viewDates, viewDate, index); // Set view date will clean up default one\n\n      setDefaultViewDates(\n      // Should always be an array\n      updateValues(defaultViewDates, null, index) || [null, null]); // Reset another one when not have value\n\n      var anotherIndex = (index + 1) % 2;\n      if (!getValue(values, anotherIndex)) {\n        newViewDates = updateValues(newViewDates, viewDate, anotherIndex);\n      }\n      setInternalViewDates(newViewDates);\n    } else if (startDate || endDate) {\n      // Reset all when has values when `viewDate` is `null` which means from open trigger\n      setInternalViewDates(null);\n    }\n  }\n  return [getViewDate, setViewDate];\n}","map":{"version":3,"names":["_slicedToArray","React","getValue","updateValues","getClosingViewDate","isSameYear","isSameMonth","isSameDecade","getStartEndDistance","startDate","endDate","picker","generateConfig","startNext","getDistance","compareFunc","start","end","getRangeViewDate","values","index","distance","useRangeViewDates","_ref","defaultDates","_React$useState","useState","_React$useState2","defaultViewDates","setDefaultViewDates","_React$useState3","_React$useState4","viewDates","setInternalViewDates","getViewDate","getNow","setViewDate","viewDate","newViewDates","anotherIndex"],"sources":["/data/messenger.client/node_modules/rc-picker/es/hooks/useRangeViewDates.js"],"sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { getValue, updateValues } from \"../utils/miscUtil\";\nimport { getClosingViewDate, isSameYear, isSameMonth, isSameDecade } from \"../utils/dateUtil\";\n\nfunction getStartEndDistance(startDate, endDate, picker, generateConfig) {\n  var startNext = getClosingViewDate(startDate, picker, generateConfig, 1);\n\n  function getDistance(compareFunc) {\n    if (compareFunc(startDate, endDate)) {\n      return 'same';\n    }\n\n    if (compareFunc(startNext, endDate)) {\n      return 'closing';\n    }\n\n    return 'far';\n  }\n\n  switch (picker) {\n    case 'year':\n      return getDistance(function (start, end) {\n        return isSameDecade(generateConfig, start, end);\n      });\n\n    case 'quarter':\n    case 'month':\n      return getDistance(function (start, end) {\n        return isSameYear(generateConfig, start, end);\n      });\n\n    default:\n      return getDistance(function (start, end) {\n        return isSameMonth(generateConfig, start, end);\n      });\n  }\n}\n\nfunction getRangeViewDate(values, index, picker, generateConfig) {\n  var startDate = getValue(values, 0);\n  var endDate = getValue(values, 1);\n\n  if (index === 0) {\n    return startDate;\n  }\n\n  if (startDate && endDate) {\n    var distance = getStartEndDistance(startDate, endDate, picker, generateConfig);\n\n    switch (distance) {\n      case 'same':\n        return startDate;\n\n      case 'closing':\n        return startDate;\n\n      default:\n        return getClosingViewDate(endDate, picker, generateConfig, -1);\n    }\n  }\n\n  return startDate;\n}\n\nexport default function useRangeViewDates(_ref) {\n  var values = _ref.values,\n      picker = _ref.picker,\n      defaultDates = _ref.defaultDates,\n      generateConfig = _ref.generateConfig;\n\n  var _React$useState = React.useState(function () {\n    return [getValue(defaultDates, 0), getValue(defaultDates, 1)];\n  }),\n      _React$useState2 = _slicedToArray(_React$useState, 2),\n      defaultViewDates = _React$useState2[0],\n      setDefaultViewDates = _React$useState2[1];\n\n  var _React$useState3 = React.useState(null),\n      _React$useState4 = _slicedToArray(_React$useState3, 2),\n      viewDates = _React$useState4[0],\n      setInternalViewDates = _React$useState4[1];\n\n  var startDate = getValue(values, 0);\n  var endDate = getValue(values, 1);\n\n  function getViewDate(index) {\n    // If set default view date, use it\n    if (defaultViewDates[index]) {\n      return defaultViewDates[index];\n    }\n\n    return getValue(viewDates, index) || getRangeViewDate(values, index, picker, generateConfig) || startDate || endDate || generateConfig.getNow();\n  }\n\n  function setViewDate(viewDate, index) {\n    if (viewDate) {\n      var newViewDates = updateValues(viewDates, viewDate, index); // Set view date will clean up default one\n\n      setDefaultViewDates( // Should always be an array\n      updateValues(defaultViewDates, null, index) || [null, null]); // Reset another one when not have value\n\n      var anotherIndex = (index + 1) % 2;\n\n      if (!getValue(values, anotherIndex)) {\n        newViewDates = updateValues(newViewDates, viewDate, anotherIndex);\n      }\n\n      setInternalViewDates(newViewDates);\n    } else if (startDate || endDate) {\n      // Reset all when has values when `viewDate` is `null` which means from open trigger\n      setInternalViewDates(null);\n    }\n  }\n\n  return [getViewDate, setViewDate];\n}"],"mappings":"AAAA,OAAOA,cAAc,MAAM,0CAA0C;AACrE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,EAAEC,YAAY,QAAQ,mBAAmB;AAC1D,SAASC,kBAAkB,EAAEC,UAAU,EAAEC,WAAW,EAAEC,YAAY,QAAQ,mBAAmB;AAE7F,SAASC,mBAAmB,CAACC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,cAAc,EAAE;EACvE,IAAIC,SAAS,GAAGT,kBAAkB,CAACK,SAAS,EAAEE,MAAM,EAAEC,cAAc,EAAE,CAAC,CAAC;EAExE,SAASE,WAAW,CAACC,WAAW,EAAE;IAChC,IAAIA,WAAW,CAACN,SAAS,EAAEC,OAAO,CAAC,EAAE;MACnC,OAAO,MAAM;IACf;IAEA,IAAIK,WAAW,CAACF,SAAS,EAAEH,OAAO,CAAC,EAAE;MACnC,OAAO,SAAS;IAClB;IAEA,OAAO,KAAK;EACd;EAEA,QAAQC,MAAM;IACZ,KAAK,MAAM;MACT,OAAOG,WAAW,CAAC,UAAUE,KAAK,EAAEC,GAAG,EAAE;QACvC,OAAOV,YAAY,CAACK,cAAc,EAAEI,KAAK,EAAEC,GAAG,CAAC;MACjD,CAAC,CAAC;IAEJ,KAAK,SAAS;IACd,KAAK,OAAO;MACV,OAAOH,WAAW,CAAC,UAAUE,KAAK,EAAEC,GAAG,EAAE;QACvC,OAAOZ,UAAU,CAACO,cAAc,EAAEI,KAAK,EAAEC,GAAG,CAAC;MAC/C,CAAC,CAAC;IAEJ;MACE,OAAOH,WAAW,CAAC,UAAUE,KAAK,EAAEC,GAAG,EAAE;QACvC,OAAOX,WAAW,CAACM,c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